﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio.Device
{
    /// <summary>
    /// 设备串口参数
    /// </summary>
    public class DeviceParaSerial : DevicePara, IDeviceParaSerial
    {
        /// <summary>
        /// 串口号
        /// </summary>
        public string PortName { get; set; }
        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate { get; set; }
        /// <summary>
        /// 数据位
        /// </summary>
        public int DataBits { get; set; }
        /// <summary>
        /// 停止位
        /// </summary>
        public StopBits StopBits { get; set; }
        /// <summary>
        /// 奇偶校验
        /// </summary>
        public Parity ParityBits { get; set; }
        /// <summary>
        /// 自动模式/启用事件接收
        /// </summary>
        public bool AutoMode { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public DeviceParaSerial() : base(DeviceConnectType.SerialPort)
        {
            this.PortName = string.Empty;
            this.BaudRate = 9600;
            this.DataBits = 8;
            this.StopBits = StopBits.None;
            this.ParityBits = Parity.None;
            this.AutoMode = false;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argDeviceName">数据设备名称</param>
        /// <param name="argDeviceCaption">数据设备描述</param>
        /// <param name="argDeviceType">设备类型名称</param>
        /// <param name="argModuleType">设备模组类型</param>
        /// <param name="argMeasureType">设备检测类型</param>
        public DeviceParaSerial(string argDeviceName, string argDeviceCaption, string argDeviceType)
            : base(argDeviceName, argDeviceCaption, argDeviceType, DeviceConnectType.SerialPort)
        {
            this.PortName = string.Empty;
            this.BaudRate = 9600;
            this.DataBits = 8;
            this.StopBits = StopBits.None;
            this.ParityBits = Parity.None;
            this.AutoMode = false;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="argDeviceName">数据设备名称</param>
        /// <param name="argDeviceCaption">数据设备描述</param>
        /// <param name="argDeviceType">设备类型名称</param>
        /// <param name="argModuleType">设备模组类型</param>
        /// <param name="argMeasureType">设备检测类型</param>
        /// <param name="argPortName">串口号</param>
        /// <param name="argBaudRate">波特率</param>
        /// <param name="argDataBits">数据位</param>
        /// <param name="argStopBits">停止位</param>
        /// <param name="argParityBits">奇偶校验</param>
        /// <param name="argAutoMode">自动模式</param>
        public DeviceParaSerial(string argDeviceName, string argDeviceCaption, string argDeviceType, DeviceModule argModuleType, 
            string argPortName, int argBaudRate, int argDataBits, StopBits argStopBits, Parity argParityBits, bool argAutoMode)
            : base(argDeviceName, argDeviceCaption, argDeviceType, DeviceConnectType.SerialPort, argModuleType)
        {
            this.PortName = argPortName;
            this.BaudRate = argBaudRate;
            this.DataBits = argDataBits;
            this.StopBits = argStopBits;
            this.ParityBits = argParityBits;
            this.AutoMode = argAutoMode;
        }

        /// <summary>
        /// 浅复制(浅克隆)
        /// </summary>
        /// <returns></returns>
        public override IDevicePara Clone()
        {
            return (DeviceParaSerial)this.MemberwiseClone();
        }

        /// <summary>
        /// 深复制(深度克隆)
        /// </summary>
        /// <returns></returns>
        public override IDevicePara CloneDeep()
        {
            return new DeviceParaSerial(DeviceName, DeviceCaption, DeviceType)
            {
                ModuleType = ModuleType,
                PortName = this.PortName,
                BaudRate = this.BaudRate,
                DataBits = this.DataBits,
                StopBits = this.StopBits,
                ParityBits = this.ParityBits,
                AutoMode = this.AutoMode
            };
        }
    }
}
